/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webanovare.bb;

import com.webanovare.model.GamesRegistry;
import com.webanovare.model.db.PlayedGame;
import com.webanovare.model.db.User;
import com.webanovare.ruzzle.mgr.GameManager;
import java.beans.*;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.inject.Named;

/**
 *
 * @author jarmju
 */
//@Named("playedgame")
@ManagedBean
@SessionScoped
public class PlayedGameBB {

    private PlayedGame game;
    private Long id;
    private User owner;
    private User opponent;
//    private String winner;
    private String loser;
    private int winnerPoints;
    private int loserPoints;
    private List<String> winnerWords;
    private List<String> loserWords; 
    
    @EJB
    GamesRegistry gr;
    
    public PlayedGameBB() {}
    
    public PlayedGameBB(PlayedGame g) {
        this.game = g;
//        this.id = g.getId();
        this.owner = g.getOwner();
        this.opponent = g.getOpponent();
        this.winnerPoints = g.getWinnerPoints();
        this.loserPoints = g.getLoserPoints();
        this.winnerWords = g.getWinnerWords();
        this.loserWords = g.getLoserWords();
        this.loser = g.getLoser().getUsername();
    }
    
    public Long getId() {
        System.out.println("getId() "+this.id);
        return this.id;
    }
    
    public void setId(Long l) {
        this.id = l;
        System.out.println("setId() l är " + l + " id är "+this.id);
        this.game = gr.getById(this.id);
        System.out.println("setId() game är " + game);
    }
    
    public String getWinner() {
        return this.game.getWinner().getUsername();
    }
    
    public String getLoser() {
        return this.game.getLoser().getUsername();
    }
    
    public List<String> getWinnerWords() {
        return this.game.getWinnerWords();
    }
    
    public List<String> getLoserWords() {
        return this.game.getLoserWords();
    }
    
    public int getWinnerPoints() {
        return this.game.getWinnerPoints();
    }
    
    public int getLoserPoints() {
        return this.game.getLoserPoints();
    }
}
